package com.eva.user.Util;

import java.sql.ResultSet;

import com.eva.jdbc.util.JdbcUtil;
import com.eva.user.pojo.User;

public class UserUtil {
	
	public static User confirmAndGetUser(String name, String pwd) throws Exception{
		String sql = "SELECT id AS userId, login_name AS loginName, user_password AS userPassword, user_code AS userCode, user_name AS userName, user_type AS userType, user_department AS userDepartment, user_introduce AS userIntroduce"
				+ "FROM user WHERE login_name = " + name + " AND user_password = " + pwd;
		ResultSet rs = JdbcUtil.getResultBySql(sql);
		if(null == rs){
			return null;
		}else{
			int count = 0;
			User user = new User();
			while(rs.next()){
				count ++;
				user.setUserId((Long)rs.getObject("userId"));
				user.setLoginName((String)rs.getObject("loginName"));
				user.setUserCode((String)rs.getObject("userCode"));
				user.setUserName((String)rs.getObject("userName"));
				user.setUserType((Integer)rs.getObject("userType"));
				user.setUserDepartment((Integer)rs.getObject("userDepartment"));
				user.setUserIntroduce((String)rs.getObject("userIntroduce"));
				if(count > 1){
					User error = new User();
					error.setUserIntroduce("查询出来的用户数量大于1，请确认帐号和密码是否正确！");
					return error;
				}
			}
			return user;
		}
	}
}
